﻿@using Think9.Models;
@model Think9.Models.IndexParmEntity
@{ ViewBag.Title = "Edit";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<form class="layui-form" lay-filter="formEdit">
    <input style="display:none" id="frm" value="@ViewBag.frm">
    <div class="layui-form-item">
        <label class="layui-form-label required">参数编码</label>
        <div class="layui-input-block layui-col-space3">
            <div class="layui-col-xs8 layui-col-sm8 layui-col-md8">
                <input type="text" name="ParmId" id="ParmId" placeholder="参数编码" autocomplete="off" class="layui-input" lay-verify="required|id" maxlength="30">
            </div>
            <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
                <select name="AutoType" id="AutoType" lay-filter="selectfilter">
                    <option value="">⇓自动生成编码</option>
                    <option value="英文">英文</option>
                    <option value="全拼">全拼</option>
                    <option value="首拼">首拼</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">参数名称</label>
        <div class="layui-input-block">
            <input type="text" name="ParmName" id="ParmName" placeholder="参数名称" autocomplete="off" class="layui-input" lay-verify="required" maxlength="30">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" required>参数类型</label>
        <div class="layui-input-block">
            <select id="DataType" name="DataType">
                <option value="string">字符</option>
                <option value="int">整数</option>
                <option value="decimal">小数</option>
                <option value="DateTime">日期</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备 注</label>
        <div class="layui-input-block">
            <input type="text" name="ParmExplain" placeholder="备注" autocomplete="off" class="layui-input" maxlength="200">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">新 建</button>&nbsp;
            <input type="checkbox" id="continue" title="连续新建">
        </div>
    </div>
</form>
<script>
    layui.use(["form", "exLayer", "exUtils"], function () {
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let $ = layui.$;

        form.render();

        form.verify({
            id: function (value, item) {
                if (!new RegExp("^[a-zA-Z]+[a-zA-Z0-9]+$").test(value)) {
                    return '编码由英文字符和数字组成，并以字母开头，不得包含中文、空格及其他字符';
                }
            }
        });

        form.on("submit(add)", function (data) {
            exUtils.ajax("/SysStats/IndexParm/Add", "post", data.field, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                    if ($("#continue").is(':checked')) {
                        $("#ParmId").val("");
                        $("#ParmName").val("");
                    }
                    else {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    }

                    if ($("#frm").val() == 'list') {
                        parent.layui.table.reload('tableId', { url: "/SysStats/IndexParm/GetListBySearch" });
                    }
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        //自动生成编码
        form.on('select(selectfilter)', function (data) {
            var name = $("#ParmName").val().trim();
            var type = data.value;
            if (name == "") {
                exLayer.yellowSighMsg("请输入名称");
                return false;
            }
            exUtils.ajax("/SysBasic/AutoCode/GetCode", "post", { name: name, type: type }, true).done(function (response) {
                $("#ParmId").val(response.extra);
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });
    });
</script>